package net.zjitc.controller;

import net.zjitc.pojo.Category;
import net.zjitc.pojo.Evaluate;
import net.zjitc.pojo.Product;
import net.zjitc.service.CategoryService;
import net.zjitc.service.ProductService;
import net.zjitc.service.impl.CategoryServiceImpl;
import net.zjitc.service.impl.ProductServiceImpl;
import net.zjitc.utils.PageBean;
import net.zjitc.utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/12/24.
 */
public class UserProduct {
    CategoryService service=new CategoryServiceImpl();
    ProductService productService=new ProductServiceImpl();
    int pageSize=12;
    @URLMapping(url = "/findByCid")
    public String findByCid(HttpServletRequest request, HttpServletResponse response){
        int page=Integer.valueOf(request.getParameter("page"));
        int cid =Integer.valueOf(request.getParameter("cid"));
        List<Category> clist=service.findAllCate();
        request.setAttribute("clist",clist);

        PageBean<Product> pageBean=productService.findPageBeanByCid(page,pageSize,cid);
        request.setAttribute("page",pageBean);
        request.setAttribute("cid",cid);
        return "/WEB-INF/user/productList.jsp";
    }
    @URLMapping(url = "/findByCsid")
    public String findByCsid(HttpServletRequest request, HttpServletResponse response){
        int page=Integer.valueOf(request.getParameter("page"));
        int csid=Integer.valueOf(request.getParameter("csid"));

        List<Category> clist=service.findAllCate();
        request.setAttribute("clist",clist);

        PageBean<Product> pageBean=productService.findPageBeanByCsid(page,pageSize,csid);
        request.setAttribute("page",pageBean);
        request.setAttribute("csid",csid);
        return "/WEB-INF/user/product_secondList.jsp";
    }

    @URLMapping(url = "/findByPid")
    public String findByPid(HttpServletRequest request, HttpServletResponse response){
        //左侧栏的数据
        List<Category> clist=service.findAllCate();
        request.setAttribute("clist",clist);

        int pid=Integer.valueOf(request.getParameter("pid"));

        Product product=productService.findByProductPid(pid);
        request.setAttribute("p",product);

        List<Evaluate> evaluate=productService.findEvaluateByPid(pid);
        request.setAttribute("evaluate",evaluate);
        request.setAttribute("pid",pid);

        return "/WEB-INF/user/product.jsp";
    }
}
